import 'package:backend.auth/domain/entities/refresh_token.dart';
import 'package:backend.core/core/domain/entities/user_role.dart';
import 'package:backend.core/core/domain/utils/uuid_generator.dart';

abstract class IssueRefreshToken {
  RefreshToken call({
    required String userId,
    required UserRole userRole,
  });
}

class IssueRefreshTokenImpl implements IssueRefreshToken {
  const IssueRefreshTokenImpl();

  @override
  RefreshToken call({
    required String userId,
    required UserRole userRole,
  }) {
    final value = UuidGenerator().generateUuid();
    final currentTime = DateTime.now().toUtc();
    final expirationTime = currentTime.add(const Duration(days: 365));

    return RefreshToken(
      userId: userId,
      userRole: userRole,
      value: value,
      expirationTime: expirationTime,
    );
  }
}
